package com.ideaaedi.zoo.example.springboot.litefeature.cs.config;

import com.ideaaedi.commonds.time.DateTimeConverter;
import com.ideaaedi.commonspring.lite.ratelimiter.RateLimitException;
import com.ideaaedi.commonspring.lite.ratelimiter.RateLimiter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class MvcExceptionAdvice {

    /**
     * 处理RateLimiterException异常
     */
    @ExceptionHandler(RateLimitException.class)
    public String handleRateLimiterException(RateLimitException rateLimiterException) {
        RateLimiter rateLimiter = rateLimiterException.getRateLimiter();
        String finalUid = rateLimiterException.getFinalUid();
        return "失败. 被限流了." + DateTimeConverter.REGULAR_DATE_TIME.now() + "\n\t" + rateLimiter + "\n\t" + finalUid;
    }

}
